<%@ include file="database_ini.jsp"%>
<%@page contentType="text/html; charset=UTF-8"%>
  <%@page import="org.json.*"%>
  <%
  	System.out.println("started:.....");
  	
  	String sql =null;
  	ResultSet rs =null;
  	String dropid = request.getParameter("dropid");
  	/*********debug*/
  	System.out.println(dropid);
  	/**********
  	
  	sql = "select CCKEY, Status from CCHDR where CCKEY = ?";
  	
  	pstmt = conn.prepareStatement(sql);
  	pstmt.setString(1 , dropid);
  	
  	rs = pstmt.executeQuery();
  	
  	while(rs.next()){
  		
  		String CCKEY = rs.getString("CCKEY");
  		String Status = rs.getString("Status");
  		System.out.println(Status + "Status");
  		if (Status == null){
	  	System.out.println("ok?");
	  	//response.setStatus(404);
	  			out.flush();
     			conn.close();
     			return;
  		}	
  	}
  	rs.close();
  	pstmt.close();
  	
  	/****************/
  	System.out.println("ok?");
  	/****************/
  	
  	JSONObject obj=new JSONObject();
  	
  	/****************/
  	JSONArray jsonChildarray = new JSONArray();
  	
  	
  	//sql = "select CCKEY, Status from CCHDR where CCKEY = ?";
  	sql = "select CCKEY, CCDROPID2, Loc, Sku, Descr, UPCCode, Lottable05, Casecnt, DisplaySystemCount, sum(Qty) as Qty from CCDET WHERE CCDROPID2 = ? "
  	+ "group by CCKEY, CCDROPID2, Loc, Sku, Descr, UPCCode, Lottable05, Casecnt, DisplaySystemCount";
  	
  	pstmt = conn.prepareStatement(sql);
  	pstmt.setString(1 , dropid);
  	
  	rs = pstmt.executeQuery();
  	while (rs.next()) {
		//String CCKEY = rs.getString("CCKEY");
  		String Loc = rs.getString("Loc");
  		String Sku = rs.getString("Sku");
  		String Descr = rs.getString("Descr");
  		String UPCCode = rs.getString("UPCCode");
  		String Lottable05 = rs.getString("Lottable05");
  		String Casecnt = rs.getString("Casecnt");
  		String DisplaySystemCount = rs.getString("DisplaySystemCount");
  		String Qty = "";
  		if(DisplaySystemCount.equalsIgnoreCase("1")){
  			Qty = rs.getString("Qty");
  		}
  		
  		
  		/****************/
  		System.out.println("Loc:" + Loc);
  		System.out.println("Sku:" + Sku);
  		System.out.println("Descr:" + Descr);
  		System.out.println("UPCCode:" + UPCCode);
  		System.out.println("Lottable05:" + Lottable05);
  		System.out.println("Casecnt:" + Casecnt);
  		System.out.println("DisplaySystemCount:" + DisplaySystemCount);
  		System.out.println("Qty:" + Qty);
  		/****************/
  		
  		JSONObject child = new JSONObject();
  		//child.put("CCKEY", CCKEY);
  		child.put("Loc", Loc);
  		child.put("Sku", Sku);
  		child.put("Descr", Descr);
  		child.put("UPCCode", UPCCode);
  		child.put("Lottable05", Lottable05);
  		child.put("Casecnt", Casecnt);
  		child.put("Qty", Qty);
  		jsonChildarray.put(child);

  	}

  	obj.put("jsonChildarray", jsonChildarray);
  	/****************/

  	/****************
  	obj.put("name","foo");
  	obj.put("num",new Integer(100));
  	obj.put("balance",new Double(1000.21));
  	obj.put("is_vip",new Boolean(true));
  	/****************/

  	out.print(obj);
  	System.out.println(obj);
  	out.flush();

  	conn.close();
  %>